package com.bgs.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bgs.pojo.Conference;
import com.bgs.pojo.Mine;
import com.bgs.pojo.Money;
import com.bgs.service.ConferenceService;
import com.bgs.tool.R;
import com.bgs.utils.LocaldatetimeUtils;
import com.bgs.vo.ConferenceVo;
import com.bgs.vo.MineVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 会议室表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-05-08
 */
@CrossOrigin
@RestController
@RequestMapping("/conference")
@Slf4j
public class ConferenceController {

    @Autowired
    private ConferenceService conferenceService;

    @ApiOperation(value = "所有会议室列表")
    @GetMapping("/findAll")
    public R findAllConference(){
        //调用service的方法实现查询所有的讲师
        List<Conference> list = conferenceService.list(null);
        return R.ok().data("list",list);
    }

    @ApiOperation(value = "所有会议室列表（后台）")
    @PostMapping("/findAllht")
    public R findAllConferenceht(@RequestBody(required = false) ConferenceVo c){
        log.info("模糊查询前端传过来的数据ConferenceVo"+c);
        PageHelper.startPage(c.getPage(),c.getLimit());
        List<ConferenceVo> list = conferenceService.listfindAllHt(c);
        PageInfo<ConferenceVo> pageInfo = new PageInfo<ConferenceVo>(list);
        return  R.ok().data("total",pageInfo.getTotal()).data("rows",pageInfo.getList());
    }

    @ApiOperation(value = "根据ID值查询会议室列表")
    @GetMapping("/getIdConference/{cid}")
    public R getIdMoney(
            @ApiParam(name = "id", value = "工资ID", required = true)
            @PathVariable Integer cid){
        Conference c = conferenceService.selectByPrimaryKey(cid);
        return R.ok().data("c",c);
    }

    @ApiOperation(value = "修改会议")
    @PostMapping("/updateCon")
    public R updateMeetingenter(@RequestBody ConferenceVo c){
        boolean flag = conferenceService.updateByPrimaryKeySelective(c);
        if (flag){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation(value ="逻辑删除")
    @DeleteMapping("removeCon/{cid}")
    public R removeemp(
            @ApiParam(name = "cid",value = "会议id",required = true)
            @PathVariable Integer cid){
        conferenceService.remove(new QueryWrapper<Conference>().eq("cid",cid));
        return R.ok();
    }


    @ApiOperation(value = "添加会议")
    @PostMapping("/addMine")
    public R addMine(
            @ApiParam(name = "Mine", value = "我的会议对象", required = true)
            @RequestBody ConferenceVo c){
        boolean save = conferenceService.insertSelective(c);
        if (save){
            return R.ok().data("mid",c.getCid());
        }else {
            return R.error();
        }
    }


}

